nexus\api\rtapi/
world.rs

1use super::RealTimeData;
2use num_enum::{IntoPrimitive, TryFromPrimitive};
3use std::net::Ipv4Addr;
4
5#[derive(Debug, Copy, Clone)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize))]
7pub struct WorldData {
8    /// Tyrian time of day.
9    pub time_of_day: Result<TimeOfDay, u32>,
10
11    /// Map id of current map.
12    pub map_id: u32,
13
14    /// Map type of current map.
15    pub map_type: Result<MapType, u32>,
16
17    /// IP address of current server.
18    pub ip_address: Ipv4Addr,
19
20    /// Location of cursor in the game world as ingame coordinates.
21    pub cursor: [f32; 3],
22}
23
24impl WorldData {
25    /// Reads world data from the given data pointer.
26    ///
27    /// # Safety
28    /// The pointer must be safe to read from.
29    pub unsafe fn read(data: *const RealTimeData) -> Self {
30        Self {
31            time_of_day: (*data).time_of_day.try_into(),
32            map_id: (*data).map_id,
33            map_type: (*data).map_type.try_into(),
34            ip_address: (*data).ip_address.into(),
35            cursor: (*data).cursor,
36        }
37    }
38}
39
40#[derive(
41    Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TryFromPrimitive, IntoPrimitive,
42)]
43#[num_enum(error_type(name = u32, constructor = From::from))]
44#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
45#[cfg_attr(
46    feature = "strum",
47    derive(
48        strum::AsRefStr,
49        strum::Display,
50        strum::EnumCount,
51        strum::EnumIter,
52        strum::IntoStaticStr,
53        strum::VariantArray,
54        strum::VariantNames
55    )
56)]
57#[repr(u32)]
58pub enum TimeOfDay {
59    Dawn,
60    Day,
61    Dusk,
62    Night,
63}
64
65#[derive(
66    Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TryFromPrimitive, IntoPrimitive,
67)]
68#[num_enum(error_type(name = u32, constructor = From::from))]
69#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
70#[cfg_attr(
71    feature = "strum",
72    derive(
73        strum::AsRefStr,
74        strum::Display,
75        strum::EnumCount,
76        strum::EnumIter,
77        strum::IntoStaticStr,
78        strum::VariantArray,
79        strum::VariantNames
80    )
81)]
82#[repr(u32)]
83pub enum MapType {
84    AutoRedirect,
85    CharacterCreation,
86    PvP,
87    GvG,
88    Instance,
89    Public,
90    Tournament,
91    Tutorial,
92    UserTournament,
93    WvWEternalBattlegrounds,
94    WvWBlueBorderlands,
95    WvWGreenBorderlands,
96    WvWRedBorderlands,
97    WVWFortunesVale,
98    WvWObsidianSanctum,
99    WvWEdgeOfTheMists,
100    PublicMini,
101    BigBattle,
102    WvWLounge,
103}